//
//  ViewController.m
//  LKAnalyticsDemo
//
//  Created by Eric MiAo on 2018/7/26.
//  Copyright © 2018年 Eric MiAo. All rights reserved.
//

#import "ViewController.h"
#import "TestViewController_1.h"
#import "TestViewController_2.h"

#import "LKAnalytics/LKAnalytics.h"

@interface ViewController ()

@end

@implementation ViewController


- (void)viewDidAppear:(BOOL)animated {
    [LKAnalytics beginLogPageView:@"首页"];
}

- (void)viewDidDisappear:(BOOL)animated {
    [LKAnalytics endLogPageView:@"首页"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"首页";
    [self initUI];
}

- (void)initUI {
    self.view.backgroundColor = [UIColor lightGrayColor];
    UIButton *pushButton_1 = [UIButton buttonWithType:UIButtonTypeCustom];
    UIButton *pushButton_2 = [UIButton buttonWithType:UIButtonTypeCustom];
    UIButton *eventButton_1 = [UIButton buttonWithType:UIButtonTypeCustom];
    UIButton *eventButton_2 = [UIButton buttonWithType:UIButtonTypeCustom];
    UIButton *crashButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    pushButton_1.frame = CGRectMake(80, 100, 120, 60);
    pushButton_2.frame = CGRectMake(210, 100, 120, 60);
    eventButton_1.frame = CGRectMake(80, 180, 120, 60);
    eventButton_2.frame = CGRectMake(210, 180, 120, 60);
    crashButton.frame = CGRectMake(80, 260, 120, 60);
    
    [pushButton_1 setTitle:@"跳转1" forState:UIControlStateNormal];
    [pushButton_2 setTitle:@"跳转2" forState:UIControlStateNormal];
    [eventButton_1 setTitle:@"自定义事件1" forState:UIControlStateNormal];
    [eventButton_2 setTitle:@"自定义事件2" forState:UIControlStateNormal];
    [crashButton setTitle:@"奔溃" forState:UIControlStateNormal];
    
    pushButton_1.backgroundColor = [UIColor orangeColor];
    pushButton_2.backgroundColor = [UIColor orangeColor];
    eventButton_1.backgroundColor = [UIColor orangeColor];
    eventButton_2.backgroundColor = [UIColor orangeColor];
    crashButton.backgroundColor = [UIColor orangeColor];
    
    pushButton_1.layer.cornerRadius = 5;
    pushButton_2.layer.cornerRadius = 5;
    eventButton_1.layer.cornerRadius = 5;
    eventButton_2.layer.cornerRadius = 5;
    crashButton.layer.cornerRadius = 5;
    
    pushButton_1.layer.borderWidth = 1;
    pushButton_2.layer.borderWidth = 1;
    eventButton_1.layer.borderWidth = 1;
    eventButton_2.layer.borderWidth = 1;
    crashButton.layer.borderWidth = 1;
    
    pushButton_1.layer.borderColor = [UIColor blackColor].CGColor;
    pushButton_2.layer.borderColor = [UIColor blackColor].CGColor;
    eventButton_1.layer.borderColor = [UIColor blackColor].CGColor;
    eventButton_2.layer.borderColor = [UIColor blackColor].CGColor;
    crashButton.layer.borderColor = [UIColor blackColor].CGColor;
    
    pushButton_1.tag = 10000;
    pushButton_2.tag = 10001;
    eventButton_1.tag = 10002;
    eventButton_2.tag = 10003;
    crashButton.tag = 10004;
    
    [self.view addSubview:pushButton_1];
    [self.view addSubview:pushButton_2];
    [self.view addSubview:eventButton_1];
    [self.view addSubview:eventButton_2];
    [self.view addSubview:crashButton];
    
    [pushButton_1 addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [pushButton_2 addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [eventButton_1 addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [eventButton_2 addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [crashButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonClick:(UIButton *)sender {
    switch (sender.tag) {
        case 10000:
            // 页面跳转
        {
            TestViewController_1 *vc = [[TestViewController_1 alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 10001:
            // 页面跳转
        {
            TestViewController_2 *vc = [[TestViewController_2 alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 10002:
            // 自定义事件
        {
            [LKAnalytics event:@"eventId_10001" label:@"A类统计" attributes:@{@"key1":@"value1", @"key2":@"value2", @"key3":@"value3", @"key4":@"value4"}];
        }
            break;
        case 10003:
            // 自定义事件
        {
            [LKAnalytics event:@"eventId_10002" label:@"A类统计" attributes:@{@"key2":@"value2"}];
        }
            break;
        case 10004:
            // 制造崩溃
        {
            [[NSArray new] objectAtIndex:10];
        }
            break;
            
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
